package struct;

/**
 * 整数类型的链表
 * @author 刘学松
 * @date 2021-03-16 11:35
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(val+"");
        ListNode nextNode = next;
        while (nextNode != null) {
            sb.append(", ").append(nextNode.val);
            nextNode = nextNode.next;
        }
        return sb.toString();
    }
}
